import React from 'react';

class ProductList extends React.Component{

	constructor(props){
		super(props);
		this.getData=this.getData.bind(this);
	}

	componentDidMount(){
		//console.log(111);
		this.props.getData("GET_PRODUCT_DATA");
	}

	getData(){
		this.props.getData("GET_PRODUCT_DATA");
	}

	addToCar(id){
		this.props.addToCar({
			type:"ADD_TO_CAR",
			id:id
		})
	}

	render(){
		var that=this;
		console.log( this.props.list);
		var todolist = this.props.list.map( (item, index) => (
            <li key={index}>
            	<span>{item.title}</span>
            	<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
            	<span>{item.price}</span>
            	<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
            	<button onClick={that.addToCar.bind(that,item.id)}>加入购物车</button>
            </li>
        ))
        
		//var list=this.getData();
		// console.log(list);
		return(
			<div>
				<button onClick={this.getData}>邱神</button>
				{todolist}
			</div>
		)
	}
}

export default ProductList;